package et.item;

import baubles.common.items.ItemRing;
import et.common.ElectricThaum;
import ic2.api.item.ElectricItem;
import ic2.api.item.IElectricItem;
import ic2.core.IC2;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;

/**
 * Created by winston_wang on 2017/7/17.
 */
public class ETItemSolarRing extends ItemRing {
    IIcon icon;
    public ETItemSolarRing(){
        setCreativeTab(ElectricThaum.tabET);
        setUnlocalizedName("solarRing");
        setTextureName("et:solar_ring");
        iconString="et:solar_ring";
    }

    @Override
    public void registerIcons(IIconRegister ir) {
        icon = ir.registerIcon("et:solar_ring");
    }

    @Override
    public IIcon getIconFromDamage(int meta) {
        return icon;
    }

    @Override
    public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
        if(IC2.platform.isSimulating()
                && itemstack.getItem() == this
                &&player.worldObj.isDaytime()) {
            EntityPlayer entityPlayer = (EntityPlayer)player;
            for(int i = 0; i < 27; ++i) {
                ItemStack stack = entityPlayer.inventory.getStackInSlot(i);
                if(stack != null && (stack.getItem() instanceof IElectricItem)) {
                    ElectricItem.manager.charge(stack,10.0D,((IElectricItem)stack.getItem()).getTier(stack),true,false);
                    if(!IC2.platform.isRendering()) {
                        entityPlayer.openContainer.detectAndSendChanges();
                    }
                }
            }
        }
    }
}
